<template>
	<div class="order_export">
		<top></top>
		<div class="center">
			<left></left>
			<div class="right kanban">
				<div class="where">当前位置：分销后台><router-link to="/order_export2">导出订单</router-link></div>
				<div style="height: 16px; width: 100%; background: #EFEFEF;"></div>
                <div class="title">导出订单</div>
                <div class="exportall" v-loading="loading" style="margin-top: 30px;">
                  <div class="xiazaili" v-for="item in list" :key="item.id">
                    <div class="flex" style=" background: rgba(0,0,0,0.1); padding:10px 20px; margin-bottom: 20px;">
                      <div style="margin-bottom: 0;">操作人：{{item.name}}</div>
                      
                      <div style="margin-bottom: 0;">生成时间：{{item.created_at}}</div>
                      
                      <div style="margin-bottom: 0;" v-if="item.status != -1">
                        <el-button type="primary" v-if="item.status == 2"  size="mini" @click="xiazai(item.id)">下载数据</el-button>
                        <el-button type="primary" v-if="item.status != 2" :loading="true" size="mini" @click="xiazai(item.id)">数据生成中,请稍后刷新页面</el-button>
                      </div>
                      <div style="margin-bottom: 0;" v-if="item.status == -1"><el-button type="text" size="mini" >异常,联系技术解决</el-button></div>
                    </div>
                    <div style="margin-bottom: 10px; padding:0 20px;">
                      {{item.remark.created_at}}
                      {{item.remark.status_updated_at}}
                      {{item.remark.ordered_at}}
                    </div>
                    <div class="flex padding:20px;"  style="padding:0 20px;">
                      <div>订单来源：{{item.remark.source}}</div>
                      <div>订单状态：{{item.remark.status}}</div>
                      <div>标旗：{{item.remark.flag}}</div>
                    </div>
                    <div class="flex"  style="padding:0 20px;">
                      <div>退款状态：{{item.remark.refund_status}}</div>
                      <div>激活状态：{{item.remark.active_status}}</div>
                      <div>外呼联系：{{item.remark.is_called}}</div>
                    </div>
                  </div>


                    <!-- <div class="list">
                       <div>生成人及条件</div><div>数据生成时间</div><div>操作</div>
                    </div>
                    <div class="list l2" v-for="item in list" :key="item.id">
                        <div>{{item.name}}</div>
                        <div>{{item.created_at}}</div>
                        <div v-if="item.status != -1"><el-button type="primary" :loading="item.status != 2" size="mini" @click="xiazai(item.id)">下载数据</el-button></div>
                        <div v-if="item.status == -1"><el-button type="text" size="mini" >异常,联系技术解决</el-button></div>
                    </div> -->
                </div>
			</div>
		</div>

        <el-dialog title="输入条件导出生产" :visible.sync="log" width="30%" :close-on-click-modal="false">
              <div style="padding-right: 30px;">
                    <el-form ref="form" @submit.native.prevent :model="form" label-width="150px">
                                <!-- <el-form-item label="通过产品名称导出:">
                                    <el-input v-model="pro" :disabled="fixpronameshow" @input="searchproname" placeholder="输入商品名称"></el-input>
                                </el-form-item> -->

                                <el-form-item label="通过订单来源导出:">
                                    <el-input v-model="pro" :disabled="fixpronameshow" @input="searchproname" placeholder="输入订单来源"></el-input>
                                </el-form-item>

                                <el-form-item label="通过产品编码导出:">
                                    <el-input v-model="code" :disabled="fixprocodeshow" @input="searchprocode" placeholder="输入产品编码"></el-input>
                                </el-form-item>
                                <el-form-item label="查询结果:">
                                    {{fixpronames}}
                                </el-form-item>
                    </el-form>

              </div>
              <div slot="footer" class="dialog-footer">
                <el-button @click="log = false">取 消</el-button>
                <el-button type="primary" @click="daochu2()" :loading="daochuing">确 定</el-button>
              </div>
        </el-dialog>


        <el-dialog title="请输入导出密码" :visible.sync="mimalog" width="400px" :close-on-click-modal="false">
              <div style="padding-right: 30px;">
                   <el-input v-model="mima" show-password placeholder="请输入导出密码"></el-input>
              </div>
              <div slot="footer" class="dialog-footer">
                <el-button size="medium" type="primary" v-if="this.daoorxia != 'dao22'" @click="mimaqueren">确 定</el-button>
                <el-button size="medium" type="primary" v-if="this.daoorxia == 'dao22'" @click="mimaqueren22">确 定</el-button>
                <el-button size="medium" type="text" @click="mimachongzhilog = true">重设密码</el-button>
              </div>
        </el-dialog>

        <el-dialog title="请设置导出密码" :visible.sync="mimasetlog" width="400px" :close-on-click-modal="false">
<!--              <div style="padding-right: 30px; margin-bottom: 20px;">
                   <el-input v-model="mimashoujihao" disabled placeholder="请输入验证码"></el-input>
              </div>
              <div style="padding-right: 30px; margin-bottom: 20px; position: relative;">
                   <el-input v-model="mimacode"  placeholder="请输入验证码"></el-input>
                   <el-button style="padding: 9px 30px; position: absolute; right: 31px; top: 1px;"  type="danger" @click="getcode" :disabled="jinyong" size="mini">{{tishi}}</el-button>
              </div> -->
              <div style="padding-right: 30px; margin-bottom: 20px;">
                   <el-input v-model="mimaset" show-password placeholder="请设置导出密码"></el-input>
              </div>
              <div style="padding-right: 30px;">
                   <el-input v-model="mimaset2" show-password placeholder="请再次输入确认导出密码"></el-input>
              </div>
              <div style="color: #DF3434; margin-top: 10px;">为了您的订单数据安全，即日起所有批量导出数据的出口需输入导出密码才可导出，请与联系店铺负责人协商设置该密码</div>
              <div slot="footer" class="dialog-footer">
                <el-button size="medium"  @click="mimasetlog = false">取 消</el-button>
                <el-button size="medium"  type="primary" @click="mimasetqueren">确 定</el-button>
              </div>
        </el-dialog>

        <el-dialog title="重设密码" :visible.sync="mimachongzhilog" width="400px" :close-on-click-modal="false">
              <div style="padding-right: 30px; margin-bottom: 20px;">
                   <el-input v-model="mimashoujihao" disabled placeholder="请输入验证码"></el-input>
              </div>
              <div style="padding-right: 30px; margin-bottom: 20px; position: relative;">
                   <el-input v-model="mimacode"  placeholder="请输入验证码"></el-input>
                   <el-button style="padding: 9px 30px; position: absolute; right: 31px; top: 1px;"  type="danger" @click="getcode" :disabled="jinyong" size="mini">{{tishi}}</el-button>
              </div>
              <div style="padding-right: 30px; margin-bottom: 20px;">
                   <el-input v-model="mimaset" show-password placeholder="请输入新密码"></el-input>
              </div>
              <div style="padding-right: 30px;">
                   <el-input v-model="mimaset2" show-password placeholder="请确认新密码"></el-input>
              </div>
              <div slot="footer" class="dialog-footer">
                <el-button size="medium" @click="mimachongzhilog = false">取 消</el-button>
                <el-button size="medium" type="primary" @click="mimaqueren2">确 定</el-button>
              </div>
        </el-dialog>


        <foot></foot>
	</div>
</template>

<script>
	import axios from "axios";
	import top from '@/components/top.vue'
    import left from '@/components/left.vue'
    import foot from '@/components/foot.vue'
	export default{
		components: {
			"left": left,
            "top": top,
            "foot": foot
		},
		name: 'kanban',
		data(){
			return{
				msg:"hello",
				options:"",
				value:"",
        list:[],
        loading:true,
        url:"",
        everyday:'',
        prolist:"",
        pro:"",
        pros:0,
        code:"",
        log:false,
        daochuing:false,
        daochuingz:"导出全部待生产",
        daochuingz2:"导出数据",
        lunxun:"",
        fixpronames:"",
        fixprocodeshow:false,
        fixpronameshow:false,
        form:{},
        fixproid:"",
        mimalog:false,
        mima:"",
        mimaid:"",
        mimasetlog:false,
        mimaset:"",
        mimaset2:"",
        mimachongzhilog:false,
        mimashoujihao:"",
        mimacode:"",
        count: 60,
        tishi:"获取验证码",
        jinyong:false,
        daoorxia:'dao',
        dao:""
			}
		},
		created() {
            this.getpro()
            this.onelist();
            this.getshoujihao()
			
			//导出密码
			if( localStorage.getItem("daochumima") != null){
				this.mima = localStorage.getItem("daochumima")
			}
		},

        destroyed() {
            // clearTimeout(this.lunxun)
        },
        methods:{

            //修改产品查询
            searchproname:function(){
                if(this.pro == ""){
                    this.fixprocodeshow = false
                    this.pros = 0
                }else{
                    this.fixprocodeshow = true
                    this.pros = 100
                    this.fixproid = ""
                }

                // this.fixpronames = "查询中..."
                // axios.get('/api/plan-market/product/get?name='+encodeURIComponent(this.pro))
                // 	.then(response => {
                //         if(response.data.msg.code != 0){
                //         	this.$message.error(response.data.msg.info);
                //         }else{
                //             if(response.data.data == null){
                //                 this.fixpronames = "销售中心无该产品信息"
                //                 this.fixproid = ""
                //             }else{
                //                 this.fixpronames = response.data.data.name
                //                 this.fixproid = response.data.data.id
                //             }
                //         }
                //     })
            },
            searchprocode:function(){
                if(this.code == ""){
                    this.fixpronameshow = false
                }else{
                    this.fixpronameshow = true
                }
                this.fixpronames = "查询中..."
                axios.get('/api/plan-market/product/get?sku='+encodeURIComponent(this.code))
                	.then(response => {
                        if(response.data.msg.code != 0){
                        	this.$message.error(response.data.msg.info);
                        }else{
                        	if(response.data.data == null){
                                this.fixpronames = "没有查询到商品"
                                this.fixproid = ""
                        	}else{
                        	    this.fixpronames = response.data.data.name
                                this.fixproid = response.data.data.id
                        	}
                        }
                    })
            },
            //轮询获取下载是否完成
            onelist:function(){
                this.getlist()
                this.loading = true
                // var that = this
                // that.lunxun = setTimeout(function(){that.onelist()},10000)
            },
            //获取所有产品
            getpro:function(){
                var that = this

              axios.get("/api/gth/products?_page_size=10000")
                .then(function(response) {
                    that.prolist = response.data.data.data
                })
            },
            getlist:function(){
                axios.get("/api/plan-market/export/log2?order_by=0")
                    .then(response =>{
                      for(let i in response.data.data.data){
                        console.log(response.data.data.data[i].remark)
                        response.data.data.data[i].remark = JSON.parse(response.data.data.data[i].remark)
                      }
                          this.list = response.data.data.data

                          this.loading = false
                          this.everyday = this.list[0].created_at
                    })
            },
            //重置密码确认
            mimaqueren2:function(){
              if(this.mimaset != this.mimaset2){
                this.$message.error("输入的密码不一致");
                return false
              }
              axios.post("/api/plan-market/shop/pwd",{mobile:this.mimashoujihao,sms_code:this.mimacode,password:this.mimaset})
                  .then(response =>{
                      if(response.data.msg.code == 0){
                          this.$message.success("密码设置成功");
                          this.mimachongzhilog = false
                      }else{
                          this.$message.error(response.data.msg.info);
                      }
                  })
            },
            //获取验证码
            getcode:function(){
              var that = this;
              var params = new URLSearchParams();
              params.append('mobile', this.mimashoujihao);
              axios.post('/api/auth/sms_code', params)
                .then(response => {
                  if(response.data.msg.code == 0){
                    this.$message({
                      message: '验证码已发送！',
                      type: 'success'
                    });
                    that.daojishi()
                  }else{
                    this.$message.error(response.data.msg.info);
                  }
                })
            },
            //倒计时功能
            daojishi:function(){
              var interval;
              interval = window.setInterval(() => {
                if(this.count <= 0){
                  window.clearInterval(interval)
                  this.tishi = "获取验证码",
                  this.jinyong = false
                  this.count = 60
                }else{
                  this.count -= 1;
                  this.tishi = this.count+"秒重新获取"
                  this.jinyong = true
                }
              }, 1000);
            },
            //获取手机号发验证码
            getshoujihao:function(){
              axios.get("/api/gth/my/shop/mobile")
                  .then(response =>{
                      if(response.data.msg.code == 0){
                          this.mimashoujihao = response.data.data
                      }else{
                          this.$message.error(response.data.msg.info);
                      }
                  })
            },
            //密码设置
            mimasetqueren:function(){
              if(this.mimaset != this.mimaset2){
                this.$message.error("输入的密码不一致");
                return false
              }

              axios.post("/api/plan-market/shop/pwd",{mobile:this.mimashoujihao,sms_code:this.mimacode,password:this.mimaset})
                  .then(response =>{
                      if(response.data.msg.code == 0){
                          this.$message.success("密码设置成功");
                          this.mimasetlog = false
                      }else{
                          this.$message.error(response.data.msg.info);
                      }
                  })
            },
            //确认密码下载
            mimaqueren:function(){
              var that = this
              if(this.daoorxia == "dao"){
                this.daochuing = true
                this.daochuingz = "生成数据中..."
                axios.post("/api/plan-market/order/export",{type:2,password:this.mima})
                  .then(function(response) {
                      if(response.data.msg.code == 0){
                            // that.loading = true
                            // that.getlist();
                            // that.daochuingz = "导出全部待生产"
                            // that.daochuing = false
                            // that.mimalog = false
                            //2021.3.1全部导出修改
                            that.$router.push({
                              path:'/order_export2'
                            })
                      }else{
                            that.$message.error(response.data.msg.info);
                            that.daochuing = false
                            that.daochuingz = "导出全部待生产"
                      }
                  });
              }else{
                axios.post("/api/plan-market/shop/log/url",{id:this.mimaid,password:this.mima})
                    .then(response =>{
                        if(response.data.msg.code == 0){

                          that.mimalog = false
                          var a = document.createElement('a');

                          a.setAttribute('href', response.data.data.local_filename);
                          a.click();
                        }else{
                            this.$message.error(response.data.msg.info);
                        }
                    })
              }

            },
            xiazai:function(id){
              this.mimaid = id
              this.daoorxia = 'xia'
              //判断有没有密码
              var that = this
              axios.get("/api/plan-market/shop/pwd")
                .then(function(response) {
                    if(response.data.msg.code == 0){
                          console.log(response)
                          if(response.data.data == ""){
                            //要设置密码
                            that.mimasetlog = true
                          }else{
                            //输入密码
                            that.mimalog = true
                          }
                    }else{
                          that.$message.error(response.data.msg.info);
                    }
                });

              //没有密码设置  有密码下载
                //地址配置,用于下载模板
                // if(window.location.href.indexOf("91haoka_platform") > -1){
                // 	console.log("线上项目，谨慎操作。")
                // 	this.url = window.location.origin+"/"
                // }else{
                // 	this.url = ""
                // }
                // var a = document.createElement('a');

                // a.setAttribute('href', this.url+url);
                // a.click();
            },
            daochu:function(){
              this.daoorxia = 'dao'
              var that = this
              axios.get("/api/plan-market/shop/pwd")
                .then(function(response) {
                    if(response.data.msg.code == 0){
                          console.log(response)
                          if(response.data.data == ""){
                            //要设置密码
                            that.mimasetlog = true
                          }else{
                            //输入密码
                            that.mimalog = true
                          }
                    }else{
                          that.$message.error(response.data.msg.info);
                    }
                });

                // this.daochuing = true
                // this.daochuingz = "生成数据中..."
                // var that = this
                // axios.get("/api/plan-market/order/export?type=2")
                //   .then(function(response) {
                //       if(response.data.msg.code == 0){
                //             that.loading = true
                //             that.getlist();
                //             that.daochuingz = "导出全部待生产"
                //             that.daochuing = false
                //       }else{
                //             that.$message.error(response.data.msg.info);
                //             that.daochuing = false
                //             that.daochuingz = "导出全部待生产"
                //       }
                //   });
            },
            mimaqueren22:function(){
              if(this.pro == "" && this.code == ""){
                  this.$message.error('至少选择一项！');
                  return false
              }
              if(this.fixproid == "" && this.pros == 0){
                  this.$message.error('请先选择产品在导出！');
                  return false
              }
              this.daochuing = true
              this.daochuingz2 = "生成数据中..."
              var that = this

              axios.post("/api/plan-market/order/export",{type:2,sp_id:this.fixproid,source:this.pro,password:this.mima})
                .then(function(response) {
                    if(response.data.msg.code == 0){
                         // that.loading = true
                         // that.log = false
                         // that.mimalog = false
                         // that.getlist();
                         // that.daochuingz2 = "导出数据"
                         // that.daochuing = false
                         //2021.3.1全部导出修改
                         this.$router.push({
                           path:'/order_export2'
                         })
                    }else{
                          that.$message.error(response.data.msg.info);
                          that.daochuingz2 = "导出数据"
                          that.daochuing = false
                    }
                });
            },
            daochu2:function(){

                this.daoorxia = 'dao22'
                var that = this
                axios.get("/api/plan-market/shop/pwd")
                  .then(function(response) {
                      if(response.data.msg.code == 0){
                            console.log(response)
                            if(response.data.data == ""){
                              //要设置密码
                              that.mimasetlog = true
                            }else{
                              //输入密码
                              that.mimalog = true
                            }
                      }else{
                            that.$message.error(response.data.msg.info);
                      }
                  });



            }
        }
	}
</script>

<style lang="scss" scoped>
	.order_export{
		margin: 0; padding: 0; background: #EFEFEF;
		.center{ width: 1366px; margin: 0 auto; display: flex; justify-content: space-between;
    .flex{ display: flex;  align-items: center; justify-content: space-between;
      div{ flex:1; margin-bottom: 10px;}
    }
    .xiazaili{ border: 1px #EAEAEA solid;  margin-bottom: 20px; }
			.kanban{ flex-basis: 1166px; background: #FFFFFF;
                .title{border-bottom: 1px #EAEAEA solid;  line-height: 45px; padding-left: 30px; font-size: 16px; background: #F9F9F9; color: #727272;}
                .my{
                	display: flex;  width: 1100px; margin:30px auto;
                	.myid{font-size: 14px; color: #DD2727; padding-left: 10px; line-height: 30px; margin-right: 20px;}

                }
                .exportall{ width: 1100px; margin:0 auto;  border-right:0; border-bottom:0;
                    .list{ display: flex; text-align: center; border-bottom:1px #EAEAEA solid;  font-size: 14px;
                        div{ flex: 1; line-height: 45px; border-right:1px #EAEAEA solid; color: #666;}
                    }
                    .l2{ font-size: 14px; color: #727272}
                }
            }
		}
	}
</style>
